/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.forms;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
import logic.ControllerAL_Main;
import logic.SO.serialization.Serialize;
import model.Administrator;
import view.controllers.*;
import view.panels.importDSpanel.*;
import view.panels.similarity.PanelSimilarity;

/**
 *
 * @author Jelena
 */
public class FrmMain extends javax.swing.JFrame {

    /**
     * Creates new form FrmMain
     */
    public FrmMain() {
        initComponents();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlMain = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        mAdministrator = new javax.swing.JMenu();
        miShowAdministators = new javax.swing.JMenuItem();
        miNewAdministrator = new javax.swing.JMenuItem();
        mDataSet = new javax.swing.JMenu();
        miShowDataSets = new javax.swing.JMenuItem();
        miImportDataSet = new javax.swing.JMenuItem();
        miExportDS = new javax.swing.JMenuItem();
        mSimilarity = new javax.swing.JMenu();
        miCheckSimilarity = new javax.swing.JMenuItem();
        mMetaAttribute = new javax.swing.JMenu();
        miAnyNewMatt = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        pnlMain.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER);

        mAdministrator.setText("Administrator");

        miShowAdministators.setText("Show all administrators");
        miShowAdministators.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miShowAdministatorsActionPerformed(evt);
            }
        });
        mAdministrator.add(miShowAdministators);

        miNewAdministrator.setText("Add new Administrators");
        miNewAdministrator.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miNewAdministratorActionPerformed(evt);
            }
        });
        mAdministrator.add(miNewAdministrator);

        jMenuBar1.add(mAdministrator);

        mDataSet.setText("DataSet");

        miShowDataSets.setText("Show all datasets");
        miShowDataSets.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miShowDataSetsActionPerformed(evt);
            }
        });
        mDataSet.add(miShowDataSets);

        miImportDataSet.setText(" Import new dataset");
        miImportDataSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miImportDataSetActionPerformed(evt);
            }
        });
        mDataSet.add(miImportDataSet);

        miExportDS.setText(" Export dataset");
        miExportDS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miExportDSActionPerformed(evt);
            }
        });
        mDataSet.add(miExportDS);

        jMenuBar1.add(mDataSet);

        mSimilarity.setText("Similarity");

        miCheckSimilarity.setText(" Check similarity");
        miCheckSimilarity.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCheckSimilarityActionPerformed(evt);
            }
        });
        mSimilarity.add(miCheckSimilarity);

        jMenuBar1.add(mSimilarity);

        mMetaAttribute.setText(" MetaAttribute");

        miAnyNewMatt.setText("Are there any new metaattribute?");
        miAnyNewMatt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAnyNewMattActionPerformed(evt);
            }
        });
        mMetaAttribute.add(miAnyNewMatt);

        jMenuBar1.add(mMetaAttribute);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void miImportDataSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miImportDataSetActionPerformed
//        ControllerUI_Main.getInstance().setActivePanel(new PanelImportDS());
        PanelImportDS panelImport = new PanelImportDS();
        ControllerUI_DSImport dsImport = new ControllerUI_DSImport();
        panelImport.setControllerImport(dsImport);
        dsImport.setPanelImportDS(panelImport);
        ControllerUI_Main.getInstance().setActivePanel(panelImport);
    }//GEN-LAST:event_miImportDataSetActionPerformed
    
    private void miShowDataSetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miShowDataSetsActionPerformed
        PanelAllDataSets pads = new PanelAllDataSets();
        ControllerUI_Main.getInstance().setActivePanel(pads);
        ControllerUI_AllDataSets.getInstance().setPanelAllDS(pads);        
    }//GEN-LAST:event_miShowDataSetsActionPerformed
    
    private void miExportDSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miExportDSActionPerformed
        PanelExportDS panelExport = new PanelExportDS();
        ControllerUI_DSExport dsExport = new ControllerUI_DSExport();
        panelExport.setControllerExport(dsExport);
        dsExport.setPanelExportDS(panelExport);
        ControllerUI_Main.getInstance().setActivePanel(panelExport);
    }//GEN-LAST:event_miExportDSActionPerformed
    
    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        try {
            Serialize.serialize(ControllerAL_Main.getInstance().getMetads());
            System.out.println("Serialize meta dataset");
        } catch (IOException ex) {
            Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_formWindowClosing
    
    private void miNewAdministratorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miNewAdministratorActionPerformed

        FrmAdministrator frmAdministrator= new FrmAdministrator();
        ControllerUI_Administrator controllerUI_Administrator= new ControllerUI_Administrator(frmAdministrator);
                frmAdministrator.setCtrlAdmin(controllerUI_Administrator);
                controllerUI_Administrator.setOdo(new Administrator());
                controllerUI_Administrator.setOef(frmAdministrator);
                frmAdministrator.getBtnRegisterAdmin().setVisible(true);
                frmAdministrator.getBtnUpdateAdmin().setVisible(false);
                frmAdministrator.setVisible(true);
        
    }//GEN-LAST:event_miNewAdministratorActionPerformed
    
    private void miAnyNewMattActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAnyNewMattActionPerformed
        PaneAnylNewMetaAttribute panma = new PaneAnylNewMetaAttribute();
        ControllerUI_Main.getInstance().setActivePanel(panma);
        
    }//GEN-LAST:event_miAnyNewMattActionPerformed
    
    private void miCheckSimilarityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCheckSimilarityActionPerformed
        PanelSimilarity pansim = new PanelSimilarity();
        ControllerUI_Similarity contr = new ControllerUI_Similarity();
        pansim.setController(contr);
        contr.setPanelSimilarity(pansim);
        ControllerUI_Main.getInstance().setActivePanel(pansim);
    }//GEN-LAST:event_miCheckSimilarityActionPerformed

    private void miShowAdministatorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miShowAdministatorsActionPerformed
        PanelAllAdmins paad= new PanelAllAdmins();
        ControllerUI_Administrator cuia= new ControllerUI_Administrator();
        cuia.setPanelAllAdmins(paad);
        paad.setControllerUI_Administrator(cuia);
        ControllerUI_Main.getInstance().setActivePanel(paad);
    }//GEN-LAST:event_miShowAdministatorsActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenu mAdministrator;
    private javax.swing.JMenu mDataSet;
    private javax.swing.JMenu mMetaAttribute;
    private javax.swing.JMenu mSimilarity;
    private javax.swing.JMenuItem miAnyNewMatt;
    private javax.swing.JMenuItem miCheckSimilarity;
    private javax.swing.JMenuItem miExportDS;
    private javax.swing.JMenuItem miImportDataSet;
    private javax.swing.JMenuItem miNewAdministrator;
    private javax.swing.JMenuItem miShowAdministators;
    private javax.swing.JMenuItem miShowDataSets;
    private javax.swing.JPanel pnlMain;
    // End of variables declaration//GEN-END:variables
    private JPanel activePanel;
    
    public void setActivePanel(JPanel newPanel) {
        if (activePanel != null) {
            this.remove(activePanel);
        }
        
        activePanel = newPanel;
        getContentPane().add(activePanel, java.awt.BorderLayout.SOUTH);        
        activePanel.setVisible(true);
        validate();
        repaint();
        pack();
    }
    
    
}
